﻿using System;
using COFE.Core;
using COFE.Core.Lister;

namespace COFE.Data.DBLink
{
    /// <summary>
    /// This provider is use when creating a new DBLink volume and virtual folder, DBCachePropertyProvider is used to access.
    /// </summary>
    internal class DBLinkTempPropertyProvider : PropertyProviderBase
    {
        private static string rootParseNameFmt = "{{{0}}}";
        private static string parseNameFmt = "{{{0}}}\\{1}";

        #region Constructor

        /// <summary>
        /// Create a DBLink Volume.
        /// </summary>
        /// <param name="listerKey"></param>
        public DBLinkTempPropertyProvider(string listerKey)
        {
            this.RegisterMethod(FileSystemInfoProperties.ParentParseName, (p) => { return ""; });
            this.RegisterMethod(FileSystemInfoProperties.FullParseName, (p) => { return String.Format(rootParseNameFmt, listerKey); });
            this.RegisterMethod(FileSystemInfoProperties.Label, (p) => { return listerKey; });
            this.RegisterMethod(FileSystemInfoProperties.IsCachable, (p) => { return true; });

            this.RegisterMethod(FileSystemInfoProperties.FileAttributes, (p) => { return FileAttributes.Directory | FileAttributes.ReadOnly; });
            this.RegisterMethod(FileSystemInfoProperties.COFEAttributes, (p) => { return COFEAttributes.Browsable | COFEAttributes.AlreadyCached; });
            this.RegisterMethod(DirectoryInfoProperties.DirectoryType, (p) => { return DirectoryTypeEnum.dtVolume; });
        }

        /// <summary>
        /// Create a DBLink Virtual folder.
        /// </summary>
        /// <param name="listerKey"></param>
        /// <param name="path"></param>
        public DBLinkTempPropertyProvider(string listerKey, string path)
        {
            this.RegisterMethod(FileSystemInfoProperties.ParentParseName, (p) => { return String.Format(parseNameFmt, listerKey, COFEPath.GetDirectoryName(path)).TrimEnd('\\'); });
            this.RegisterMethod(FileSystemInfoProperties.FullParseName, (p) => { return String.Format(parseNameFmt, listerKey, path); });
            this.RegisterMethod(FileSystemInfoProperties.Label, (p) => { return COFEPath.GetFileName(path); });
            this.RegisterMethod(FileSystemInfoProperties.IsCachable, (p) => { return true; });

            this.RegisterMethod(FileSystemInfoProperties.FileAttributes, (p) => { return FileAttributes.Directory;  });
            this.RegisterMethod(FileSystemInfoProperties.COFEAttributes, (p) => { return COFEAttributes.Browsable | COFEAttributes.AlreadyCached; });
            this.RegisterMethod(DirectoryInfoProperties.DirectoryType, (p) => { return DirectoryTypeEnum.dtFolder; });
        }

        #endregion

        #region Methods

        #endregion

        #region Data

        #endregion

        #region Public Properties

        #endregion
    }
}
